home *** CD-ROM | disk | FTP | other *** search
- { dynaicon.pas -- Display an animated icon guage }
-
- program DynaIcon;
-
- uses WinTypes, WinProcs, WObjects;
-
- const
-
- timer_ID = 1; { Local timer id number }
- timer_Interval = 500; { Milliseconds between timer events }
- level_Increment = 16; { Number of gauge increments }
-
- type
-
- DynaIconApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PDynaIconWindow = ^DynaIconWindow;
- DynaIconWindow = object(TWindow)
- Level: Integer;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure GetGaugeRect(var R: TRect;
- var Increment: Integer);
- procedure GetWindowClass(var AWndClass: TWndClass);
- virtual;
- procedure SetupWindow;
- virtual;
- procedure WMDestroy(var Msg: TMessage);
- virtual wm_First + wm_Destroy;
- procedure WMTimer(var Msg: TMessage);
- virtual wm_First + wm_Timer;
- procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
- virtual;
- end;
-
-
- { DynaIconApplication }
-
- {- Initialize DynaIconApplication object's window }
- procedure DynaIconApplication.InitMainWindow;
- begin
- MainWindow := New(PDynaIconWindow, Init(nil, 'DynaIcon'))
- end;
-
-
- { DynaIconWindow }
-
- {- Construct DynaIconWindow object }
- constructor DynaIconWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- Level := 0
- end;
-
- {- Modify window class to generate wm_Paint messages for icon }
- procedure DynaIconWindow.GetWindowClass(var AWndClass: TWndClass);
- begin
- TWindow.GetWindowClass(AWndClass);
- AWndClass.HIcon := 0
- end;
-
- {- Initialize the window's actions }
- procedure DynaIconWindow.SetupWindow;
- begin
- TWindow.SetupWindow;
- SetTimer(hWindow, timer_ID, timer_Interval, nil)
- end;
-
- {- Intercept wm_Destroy message }
- procedure DynaIconWindow.WMDestroy(var Msg: TMessage);
- begin
- KillTimer(hWindow, timer_ID);
- TWindow.WMDestroy(Msg)
- end;
-
- {- Calculate gauge rectangle }
- procedure DynaIconWindow.GetGaugeRect(var R: TRect;
- var Increment: Integer);
- begin
- GetClientRect(HWindow, R);
- with R do
- begin
- if not IsIconic(HWindow) then
- begin
- Left := Left + 10;
- Top := Top + 10;
- Right := Right - 10;
- Bottom := Top + 20;
- while (Right - Left) mod level_Increment <> 0 do
- Dec(Right)
- end;
- Increment := (Right - Left) div level_Increment;
- if Increment <= 0 then Increment := 0
- end
- end;
-
- {- Execute one "tick" of the timer's clock }
- procedure DynaIconWindow.WMTimer(var Msg: TMessage);
- var
- R: TRect;
- N: Integer;
- begin
- GetGaugeRect(R, N);
- if Level >= level_Increment then
- begin { Reset Level, causing entire gauge to be redrawn }
- MessageBeep(0);
- Level := 0
- end else
- begin { Count passes and calculate gauge area to redraw }
- Inc(Level);
- with R do
- begin
- Right := Left + Level * N;
- Left := Left + (Level - 1) * N
- end
- end;
- InvalidateRect(HWindow, @R, false) { Redraw TRect bounded by R }
- end;
-
- {- Paint demonstration gauge }
- procedure DynaIconWindow.Paint(PaintDC: HDC; var PaintInfo:
- TPaintStruct);
- var
- R: TRect;
- I, N, X: Integer;
- Brush, OldBrush: HBrush;
- Pen, OldPen: HPen;
- begin
- Brush := GetStockObject(white_Brush);
- OldBrush := SelectObject(PaintDC, Brush);
- Pen := GetStockObject(black_Pen);
- OldPen := SelectObject(PaintDC, Pen);
- GetGaugeRect(R, N);
- with R do
- begin
- Rectangle(PaintDC, Left, Top, Right, Bottom); { Outline }
- for I := 1 to level_Increment do
- begin
- X := Left + I * N;
- if (not IsIconic(HWindow)) and (I < level_Increment) then
- begin
- MoveTo(PaintDC, X, Top - 2); { Division lines }
- LineTo(PaintDC, X, Bottom + 2)
- end;
- if I <= Level then { Paint filled areas }
- begin
- SelectObject(PaintDC, GetStockObject(black_Brush));
- Rectangle(PaintDC, Left + (I - 1) * N, Top, X, Bottom)
- end
- end
- end;
- SelectObject(PaintDC, OldBrush);
- SelectObject(PaintDC, OldPen)
- end;
-
- var
-
- DynaIconApp: DynaIconApplication;
-
- begin
- DynaIconApp.Init('DynaIconApp');
- DynaIconApp.Run;
- DynaIconApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 3/07/1991
- ---------------------------------------------------------------}
-